<?php
namespace app\admin\controller;
use app\admin\validate\UserValidate;
use app\admin\model\AdvertModel;
use think\facade\Request;
/**
 * 广告控制器
 * Class Advert
 * @package app\admin\controller
 */
class Advert extends UserValidate{
    public function index(){
        $area = input('area');
        $data = (new AdvertModel)->index($area);
        $this->assign('list',$data);
        return view();
    }


    /**
     *修改---渲染
     * @param $id
     * @return \think\response\View
     */
    public function advertup($id){
        if ($id){
            $ad_id = (new AdvertModel)->adcheck($id);
            $this->assign('ad_id',$ad_id);
            return view();
        }
        $this->error('缺少重要参数');
    }

    /**
     * 修改
     */
    public function advertups(){
        if (!empty($_FILES['url']['name'])){
            $file = request()->file('url');

            if (!$file){
                $this->error('请检查上传内容');
            }
            $target = $file->rule('md5')->validate(['size'=>900000,'ext'=>'jpg,png,gif,mp4'])->move( '../public/image',time());
            if ($target == false){
                $this->error('请检查上传内容');
            }
            $translation = "/image/" .$target->getsaveName();
            $value_add = (new AdvertModel)->dvertrepair(Request::post(),$translation);
            if ($value_add === true){
                $this->success('修改成功');
            }
                $this->error($value_add);
        }
        $value_add = (new AdvertModel)->dvertrepair(Request::post(),$translation = null);
        if ($value_add === true){
            $this->success('修改成功');
        }
        $this->error($value_add);
    }
}